package colour;

/**
 *
 * @author Michael Hanns
 *
 */
public class ColourUtil {

    // Colour codes
    private final static int blackCode = 0;
    private final static int redCode = 1;
    private final static int greenCode = 2;
    private final static int yellowCode = 3;
    private final static int blueCode = 4;
    private final static int magentaCode = 5;
    private final static int cyanCode = 6;
    private final static int whiteCode = 7;
    private final static int greyCode = 9;
    // Contants
    public final static Colour black = new Colour(blackCode, true);
    public final static Colour red = new Colour(redCode, true);
    public final static Colour green = new Colour(greenCode, true);
    public final static Colour yellow = new Colour(yellowCode, true);
    public final static Colour blue = new Colour(blueCode, true);
    public final static Colour magenta = new Colour(magentaCode, true);
    public final static Colour cyan = new Colour(cyanCode, true);
    public final static Colour white = new Colour(whiteCode, true);
    public final static Colour grey = new Colour(greyCode, true);
    public final static Colour darkBlack = new Colour(blackCode, false);
    public final static Colour darkRed = new Colour(redCode, false);
    public final static Colour darkGreen = new Colour(greenCode, false);
    public final static Colour darkYellow = new Colour(yellowCode, false);
    public final static Colour darkBlue = new Colour(blueCode, false);
    public final static Colour darkMagenta = new Colour(magentaCode, false);
    public final static Colour darkCyan = new Colour(cyanCode, false);
    public final static Colour darkWhite = new Colour(whiteCode, false);
    public final static Colour darkGrey = new Colour(greyCode, false);
    
    public final static Colour player = magenta;
    public final static Colour item = cyan;
    public final static Colour mobile = red;
    public final static Colour trigger = white;
    public final static Colour currency = yellow;
    public final static Colour roomTitle = green;
    public final static Colour roomDescription = grey;
    
    public final static Colour locked = red;
    public final static Colour closed = yellow;
    public final static Colour open   = green;
    
    
    public final static Colour channel = darkMagenta;
    
    public final static Colour value = white;
    public final static Colour damage = darkRed;
    public final static Colour defaultColour = grey;
   
    public final static Colour[] criticalHit = new Colour[] {ColourUtil.yellow, ColourUtil.red};
    public final static Colour[] criticalHeal = new Colour[] {ColourUtil.white, ColourUtil.grey};
    
    public static String colourise(String input, Colour colour) {
        if (!colour.isBright()) {
            return ((char) 27) + "[0;3" + colour.getColour() + "m" + input
                    + ((char) 27) + "[0;39m";
        } else {
            return colourise(input, colour.getColour());
        }
    }

    public static String colourise(String input, int colour) {
        return ((char) 27) + "[1;3" + colour + "m" + input
                + ((char) 27) + "[0;39m";
    }

    public static String colouriseAlternate(String input, Colour[] colour) {
        String out = "";
        int colourCount = 0;
        int brightCount = 0;

        if (colour.length == 0) {
            return input;
        }

        for (int x = 0; x < input.length(); x++) {
            out += colourise(input.charAt(x) + "", colour[colourCount]);
            colourCount++;
            if (colourCount >= colour.length) {
                colourCount = 0;
            }
        }

        return out;
    }
}
